class Face < ActiveRecord::Base
  MAX_IMAGE_SIZE=51200        #Maximize picture size is 51200
  
  belongs_to  :user
  validates_format_of :content_type,
                      :with => /^image/,
                      :message => "You can only upload pictures"
                      
  def uploaded_face=(picture_field)
    self.filename = base_part_of(picture_field.original_filename)
    self.content_type = picture_field.content_type.chomp
    self.data = picture_field.read
  end
  
  def base_part_of(file_name)
    File.basename(file_name).gsub(/[^\w._-]/, '' )
  end

  def validate 
      if self.data!= nil
         errors.add("", "File is Bigger than 50KB") if self.data.size > MAX_IMAGE_SIZE
      end
  end
end
